/*
 * @Descripttion: 重写 ElMessage ,防止多次提示
 * @version:
 * @Author: HYH
 * @Date: 2021-09-24 18:25:12
 * @LastEditors: HYH
 * @LastEditTime: 2022-07-19 11:00:42
 */
import { ElMessage } from 'element-plus'
let messageInstance: any = null
const resetMessage: any = (options: string) => {
  if (messageInstance) {
    messageInstance.close()
  }
  messageInstance = ElMessage(options)
}
;['error', 'success', 'info', 'warning'].forEach(type => {
  resetMessage[type] = (options: any) => {
    if (typeof options === 'string') {
      options = {
        message: options
      }
    }
    options.type = type
    return resetMessage(options)
  }
})
export default resetMessage
